package com.kaussoft.lolblog.vo;

import java.io.Serializable;
import java.util.Set;

/** 
 * 		@hibernate.class
 * 		 table="ACCOUNT"
 */
public class Account implements Serializable {
	
	// serialVersionUID
	private static final long serialVersionUID = 1L;
	
	// hashCode
	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private Integer accountid;
	
	// fields
	private String accountname;
	private String accountpass;
	
	// collections
	private Set<Wblog> wblogs;
	
	/** default constructor */
	public Account() {
		
	}
	
	/** primary key constructor */
	public Account(Integer accountid) {
		this.setAccountid(accountid);
	}
	
	/** required fields constructor */
	public Account(Integer accountid, String accountname, String accountpass) {
		this.setAccountid(accountid);
		this.setAccountname(accountname);
		this.setAccountpass(accountpass);
	}

	/*		for SQLServer & MySQL & Derby & HSQL & Firebird & PostgreSQL
	 * 		@hibernate.id
	 * 		 column="ACCOUNT_ID"
	 * 		 generator-class="native"
	 * 		 type="java.lang.Integer"
	 * 		 unsaved-value=null
	 * 		@hibernate.generator-param name="sequence" value="SQ_ACCOUNT_ID"  //Only Firebird&PostgreSQL need this
	 */
	/**
	 * 		@hibernate.id
	 * 		 column="ACCOUNT_ID"
	 * 		 generator-class="native"
	 * 		 type="java.lang.Integer"
	 * 		 unsaved-value=null
	 * 		@hibernate.generator-param name="sequence" value="SQ_ACCOUNT_ID"
	 */
	public Integer getAccountid() {
		return accountid;
	}

	public void setAccountid(Integer accountid) {
		this.accountid = accountid;
		this.hashCode = Integer.MIN_VALUE;
	}

	/**
	 * 		@hibernate.property
	 * 		 column="ACCOUNT_NAME"
	 * 		 length="10"
	 */
	public String getAccountname() {
		return accountname;
	}

	public void setAccountname(String accountname) {
		this.accountname = accountname;
	}

	/**
	 * 		@hibernate.property
	 * 		 column="ACCOUNT_PASS"
	 *		 length="10"
	 */
	public String getAccountpass() {
		return accountpass;
	}

	public void setAccountpass(String accountpass) {
		this.accountpass = accountpass;
	}
	
	/**
	 * 		@hibernate.set
	 * 		 lazy="true"
     *       inverse="true"
     *       cascade="all-delete-orphan"
     *      @hibernate.key
     *       column="ACCOUNT_ID"
     *      @hibernate.one-to-many
     *       class="com.kaussoft.lolblog.vo.Wblog"
	 */
	public Set<Wblog> getWblogs() {
		return wblogs;
	}

	public void setWblogs(Set<Wblog> wblogs) {
		this.wblogs = wblogs;
	}
	
	public boolean addToWblogs(Object obj) {
		if (null == obj)
			return false;
		if (!(obj instanceof Wblog)) 
			return false;
		else {
			Wblog aObj = (Wblog)obj;
			if (null == this.wblogs) 
				this.wblogs = new java.util.HashSet<Wblog>();
			return this.wblogs.add(aObj);
		}
	}
	
	public boolean equals(Object obj) {
		if (null == obj) 
			return false;
		if (!(obj instanceof Account)) 
			return false;
		else {
			Account aObj = (Account)obj;
			if (null == this.getAccountid() || null == aObj.getAccountid()) 
				return false;
			else 
				return (this.getAccountid().equals(aObj.getAccountid()));
		}
	}
	
	public int hashCode() {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getAccountid()) 
				return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":" + this.getAccountid().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}

	public String toString() {
		return super.toString();
	}

}
